#include "netdisk.h"

// 实现 pwd 命令，用于打印当前工作目录
int pwdFunc(Stack_t dir, int netfd){
    tran_t working_dir;
    bzero(&working_dir, sizeof(tran_t));
    
    travel_stack(dir, working_dir.data);
    strcat(working_dir.data, "\n");

    working_dir.length = strlen(working_dir.data);

    int canSend = 0;
    send(netfd, &canSend, sizeof(int), MSG_NOSIGNAL);

    send(netfd, &working_dir, sizeof(working_dir.length)+
         working_dir.length, MSG_NOSIGNAL);
    
    return 0;
}

void func_error_check(int ret, int netfd){
    char error1[] = "wrong argument!\n";
    int error_length = strlen(error1);
    if(ret == -1){
        send(netfd, &ret, sizeof(ret), MSG_NOSIGNAL);       
        send(netfd, &error_length, sizeof(int), MSG_NOSIGNAL);
        send(netfd, error1, error_length, MSG_NOSIGNAL);
    }else{
        send(netfd, &ret, sizeof(ret), MSG_NOSIGNAL);
    }
}
